﻿using System;

class FormulaBit1
{
    static void Main(string[] args)
    {
        System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;

        int[,] grid = new int[8, 8];
        for (int row = 0; row < 8; row++)
        {
            int element = int.Parse(Console.ReadLine());
            for (int column = 0; column <= 7; column++)
            {
                grid[row, column] = element & 1;
                element >>= 1;
            }
        }

        ////comment
        //for (int row = 0; row < 8; row++)
        //{
        //    for (int column = 0; column <= 7; column++)
        //    {
        //        Console.Write(grid[row, column] + " ");

        //    }
        //    Console.WriteLine();
        //}
        ////comment


        int trackLength = 1;
        int trackTurns = 0;
        bool notInterrupted = true;
        int currentRow = 0;
        int currentColumn = 0;
        string prevDirection = "south";
        string currentDirection = "south";

        if (grid[currentRow, currentColumn] == 1)
        {
            notInterrupted = false;
            trackLength = 0;
        }
        while (notInterrupted && (currentRow + currentColumn != 14))
        {
            //grid[currentRow, currentColumn] = 3;
            switch (currentDirection)
            {
                
                case "west":
                    {
                        if (currentColumn < 7 && (grid[currentRow, currentColumn + 1] == 0))
                        {
                            trackLength++;
                            currentColumn++;
                        }
                        else
                        {
                            if (prevDirection == "south" && currentRow > 0 && grid[currentRow - 1, currentColumn] == 0)
                            {
                                currentRow--;
                                trackLength++;
                                trackTurns++;
                                prevDirection = "west";
                                currentDirection = "north";
                            }
                            else if (prevDirection == "north" && currentRow < 7 && grid[currentRow + 1, currentColumn] == 0)
                            {
                                currentRow++;
                                trackLength++;
                                trackTurns++;
                                prevDirection = "west";
                                currentDirection = "south";
                            }
                            else
                            {
                                notInterrupted = false;
                            }
                        }
                        break;
                    }                
                case "south":
                    {
                        if (currentRow < 7 && (grid[currentRow + 1, currentColumn] == 0))
                        {
                            trackLength++;
                            currentRow++;
                        }
                        else
                        {
                            if ((currentColumn + 1 < 8) && grid[currentRow, currentColumn + 1] == 0)
                            {
                                currentColumn++;
                                trackLength++;
                                trackTurns++;
                                prevDirection = "south";
                                currentDirection = "west";
                            }
                            else
                            {
                                notInterrupted = false;
                            }
                        }
                        break;
                    }
                case "north":
                    {
                        if (currentRow > 0 && (grid[currentRow-1, currentColumn] == 0))
                        {
                            trackLength++;
                            currentRow--;
                        }
                        else
                        {
                            if ((currentColumn + 1 < 8) && grid[currentRow, currentColumn + 1] == 0)
                            {
                                currentColumn++;
                                trackLength++;
                                trackTurns++;
                                prevDirection = "north";
                                currentDirection = "west";
                            }
                            else
                            {
                                notInterrupted = false;
                            }
                        }
                        break;
                    }
                
            }
            

        }

        ////comment
        //Console.WriteLine();
        //for (int row = 0; row < 8; row++)
        //{
        //    for (int column = 0; column <= 7; column++)
        //    {
        //        Console.Write(grid[row, column] + " ");

        //    }
        //    Console.WriteLine();
        //}
        //Console.WriteLine();
        ////comment

        if (notInterrupted)
        {
            Console.WriteLine(trackLength + " " + trackTurns);
        }
        else 
        {
            Console.WriteLine("No " + trackLength);
        }
    }
}
